import com.android.build.gradle.LibraryExtension
import com.bo.apps.ApplicationPluginConfig
import com.bo.apps.configureKotlinAndroid
import com.bo.apps.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

//https://therouter.cn/docs/2022/11/23/01
class AndroidLibraryConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply(ApplicationPluginConfig.androidLibraryAndroid)
                apply(ApplicationPluginConfig.androidKotlinAndroid)
                apply("kotlin-parcelize")
                apply("com.google.devtools.ksp")
                apply("kotlin-kapt")

            }

            extensions.configure<LibraryExtension> {
                configureKotlinAndroid(this)
                defaultConfig.targetSdk = ApplicationPluginConfig.targetSdkVersion
            }

            dependencies {
                "implementation"(libs.findLibrary("androidx.core.ktx").get())
                "implementation"(libs.findLibrary("androidx.appcompat").get())
                "implementation"(libs.findLibrary("androidx.activity").get())
                "implementation"(libs.findLibrary("androidx.fragment").get())
                "implementation"(libs.findLibrary("google.android.material").get())
                "implementation"(libs.findLibrary("therouter.router").get())
                "implementation"(libs.findLibrary("androidx.activity").get())
                "kapt"(libs.findLibrary("therouter.router.apt").get())
            }

        }
    }
}